<?php
if($_POST['submit_termin']!=true) echo "";
else{
	$term=trim(addslashes(htmlspecialchars($_POST['term'])));
	$dict_descr=trim(addslashes(htmlspecialchars($_POST['dict_descr'])));
	$cat=$_POST['cat'];
	$time=time();
	$from_who=$_SESSION['username'];
	
	$sel_u = mysql_query('SELECT teacher_to FROM users WHERE username = "'.$_SESSION['username'].'"');
	$row_u = mysql_fetch_assoc($sel_u);
	
	if(empty($term)||empty($dict_descr)){
	   echo '<p class="error">Моля, попълнете ВСИЧКИ полета!</p>';
	}
	else{
	if(strlen($term)<2){
	   echo '<p class="error">Кратко име на термина!</p>';
	} else {
	$s_n='SELECT term FROM termin WHERE term="'.$term.'"';
	$r_n=mysql_query($s_n);
	
	if(mysql_num_rows($r_n)!=0){
	   echo '<p class="error">Терминът е вече в базата данни!</p>';
	}
	else{
	   $insert_into_dict=mysql_query('INSERT INTO termin(term, term_descr, cat, date_added, from_who, module)
	   VALUES("'.$term.'","'.$dict_descr.'","'.$cat.'",'.$time.',"'.$from_who.'", "'.$row_u['teacher_to'].'")');
	   echo '<p class="success">Успешен запис!</p>';
	}
	}
	}
	}
?>